Dynomotion

Group: DynoMotion Message: 5013 From: michaelthomasn Date: 5/21/2012
Subject: Feedhold with external pushbutton
Tom,

I want to have the feedhold activated by pushing a button, then resume motion by pushing the button again.

I think i figured out how to do it.

I wondered if you would comment on my c program.

It seems unnecessarily complicated to me.....but I couldn't seem to get my non programmer head to come up with anything better.

http://tech.groups.yahoo.com/group/DynoMotion/files/michaelthomas/

I would also like to start a kmotion cnc g code program with an external button, too.

Is there a command for that?

Mike
Group: DynoMotion Message: 5016 From: Tom Kerekes Date: 5/21/2012
Subject: Re: Feedhold with external pushbutton
Hi Mike,
 
There were quite a few issues :}
 
But I think something else to consider is switch bounce.  Usually mechanical switches do not switch on and off cleanly.  Sometimes it doesn't matter with something like EStop but here where you want to toggle something on and off switch bounce can be a problem.  A noise spike might want to be ignored as well.  So I added a helper function to debounce switches.  This function will handle the messy details and return one of 3 values:  0 if the switch just transitioned low, 1 if it just transitioned high, and -1 if there was no change.  The same (Debounce) function can be used for any number of switches but 3 global variables must be created for each switch and they must be passed to the function.  The function uses these 3 variables to remember what has been going on with that particular switch.  The DBTIME is set at 300 samples which would be about 60ms.
 
I've uploaded a C Program (FeedHoldCycleStart.c) to your folder that watches two switches.  One for FeedHold and One for Cycle Start (I assume that is what you meant by "Start  GCode").
 
You may need to tweak it for your bit numbers and polarities.
 
Regards
TK
  

Group: DynoMotion Message: 5017 From: michaelthomasn Date: 5/21/2012
Subject: Re: Feedhold with external pushbutton
Good grief!

That is a bunch of code I can't make any sense of....lol.

I mocked up a similar setup of what I posted on my Arduino, and it works most of the time....probably bounce....but i had an idea that I read about for that.

I guess the codes really aren't too similar between the two.

This is going to be tough, because I want to understand what to do rather than rely on you to make what I need. I have 3 other machines that are going to have some special needs and I definitely don't want to pester you too much.

Do you have any recommended reading?

Thanks again,

Mike






--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Mike,
>  
> There were quite a few issues :}
>  
> But I think something else to consider is switch bounce.  Usually mechanical switches do not switch on and off cleanly.  Sometimes it doesn't matter with something like EStop but here where you want to toggle something on and off switch bounce can be a problem.  A noise spike might want to be ignored as well.  So I added a helper function to debounce switches.  This function will handle the messy details and return one of 3 values:  0 if the switch just transitioned low, 1 if it just transitioned high, and -1 if there was no change.  The same (Debounce) function can be used for any number of switches but 3 global variables must be created for each switch and they must be passed to the function.  The function uses these 3 variables to remember what has been going on with that particular switch.  The DBTIME is set at 300 samples which would be about 60ms.
>  
> I've uploaded a C Program (FeedHoldCycleStart.c) to your folder that watches two switches.  One for FeedHold and One for Cycle Start (I assume that is what you meant by "Start  GCode").
>  
> You may need to tweak it for your bit numbers and polarities.
>  
> Regards
> TK
>   
>
> From: michaelthomasn <michaelniksch@...>
> To: DynoMotion@yahoogroups.com
> Sent: Monday, May 21, 2012 12:24 PM
> Subject: [DynoMotion] Feedhold with external pushbutton
>
>
>  
> Tom,
>
> I want to have the feedhold activated by pushing a button, then resume motion by pushing the button again.
>
> I think i figured out how to do it.
>
> I wondered if you would comment on my c program.
>
> It seems unnecessarily complicated to me.....but I couldn't seem to get my non programmer head to come up with anything better.
>
> http://tech.groups.yahoo.com/group/DynoMotion/files/michaelthomas/
>
> I would also like to start a kmotion cnc g code program with an external button, too.
>
> Is there a command for that?
>
> Mike
>
Group: DynoMotion Message: 5018 From: Tom Kerekes Date: 5/21/2012
Subject: Re: Feedhold with external pushbutton
Come on Mike It isn't really that bad :}
 
Hopefully if you don't completely understand the debounce function you can easily understand how to use it.  Just call it passing the bit or condition you wish to debounce and it returns -1, 0, or 1.
 
here are some C reference links in a previous post:
 
 
Here are some videos:
 
 
Most of the on-line videos assume you will be running C on the PC where there is disk and keyboard and a PC based Compiler.  KFLOP is a bit different environment but the basic C syntax of the language is the same.  His videos that closely apply to KFLOP programs would be:
 
#3 Constants
 
#4 Operators
 
#5 Variables
 
#6 Outputting (printf)
 
#8 Conditions
 
#9 If statement
 
#10 if else
 
#11 if else if
 
#12 while loop
 
#13 for loop
 
#14 do while loop
 
#23 Functions
 
#24 Function Arguments
 
#25 Returning values
 
 
TK
 
 

 
From: michaelthomasn <michaelniksch@...>
To: DynoMotion@yahoogroups.com
Sent: Monday, May 21, 2012 6:42 PM
Subject: [DynoMotion] Re: Feedhold with external pushbutton

 

Good grief!

That is a bunch of code I can't make any sense of....lol.

I mocked up a similar setup of what I posted on my Arduino, and it works most of the time....probably bounce....but i had an idea that I read about for that.

I guess the codes really aren't too similar between the two.

This is going to be tough, because I want to understand what to do rather than rely on you to make what I need. I have 3 other machines that are going to have some special needs and I definitely don't want to pester you too much.

Do you have any recommended reading?

Thanks again,

Mike

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Mike,
>  
> There were quite a few issues :}
>  
> But I think something else to consider is switch bounce.  Usually mechanical switches do not switch on and off cleanly.  Sometimes it doesn't matter with something like EStop but here where you want to toggle something on and off switch bounce can be a problem.  A noise spike might want to be ignored as well.  So I added a helper function to debounce switches.  This function will handle the messy details and return one of 3 values:  0 if the switch just transitioned low, 1 if it just transitioned high, and -1 if there was no change.  The same (Debounce) function can be used for any number of switches but 3 global variables must be created for each switch and they must be passed to the function.  The function uses these 3 variables to remember what has been going on with that particular switch.  The DBTIME is set at 300 samples which would be about 60ms.
>  
> I've uploaded a C Program (FeedHoldCycleStart.c) to your folder that watches two switches.  One for FeedHold and One for Cycle Start (I assume that is what you meant by "Start  GCode").
>  
> You may need to tweak it for your bit numbers and polarities.
>  
> Regards
> TK
>   
>
> From: michaelthomasn <michaelniksch@...>
> To: DynoMotion@yahoogroups.com
> Sent: Monday, May 21, 2012 12:24 PM
> Subject: [DynoMotion] Feedhold with external pushbutton
>
>
>  
> Tom,
>
> I want to have the feedhold activated by pushing a button, then resume motion by pushing the button again.
>
> I think i figured out how to do it.
>
> I wondered if you would comment on my c program.
>
> It seems unnecessarily complicated to me.....but I couldn't seem to get my non programmer head to come up with anything better.
>
> http://tech.groups.yahoo.com/group/DynoMotion/files/michaelthomas/
>
> I would also like to start a kmotion cnc g code program with an external button, too.
>
> Is there a command for that?
>
> Mike
>



Group: DynoMotion Message: 5028 From: michaelthomasn Date: 5/22/2012
Subject: Re: Feedhold with external pushbutton
Those are some very helpful links....Thanks.

I can't absorb too much at one sitting, though.

I found more than a few helpful things today, so far. :)

I know it's not your business to grade peoples c efforts....but if you have any time to do so, and are in need of a chuckle at my expense..... I would be grateful.

After some new found knowledge, I revised the crap program that I
originally asked you to critique.

http://tech.groups.yahoo.com/group/DynoMotion/files/michaelthomas/

I will surely use what you gave me, I just want to see if I got closer to making some computer sense.

I suppose when I have my mill moving around, I can see for myself.

Thanks again,

Mike
--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Come on Mike It isn't really that bad :}
>  
> Hopefully if you don't completely understand the debounce function you can easily understand how to use it.  Just call it passing the bit or condition you wish to debounce and it returns -1, 0, or 1.
>  
> here are some C reference links in a previous post:
>  
> http://tech.groups.yahoo.com/group/DynoMotion/message/3020
>  
> Here are some videos:
>  
> http://www.cplusplustutor.com/
>  
> Most of the on-line videos assume you will be running C on the PC where there is disk and keyboard and a PC based Compiler.  KFLOP is a bit different environment but the basic C syntax of the language is the same.  His videos that closely apply to KFLOP programs would be:
>  
> #3 Constants
>  
> #4 Operators
>  
> #5 Variables
>  
> #6 Outputting (printf)
>  
> #8 Conditions
>  
> #9 If statement
>  
> #10 if else
>  
> #11 if else if
>  
> #12 while loop
>  
> #13 for loop
>  
> #14 do while loop
>  
> #23 Functions
>  
> #24 Function Arguments
>  
> #25 Returning values
>  
>  
> TK
>  
>  
>
>  
>
> ________________________________
> From: michaelthomasn <michaelniksch@...>
> To: DynoMotion@yahoogroups.com
> Sent: Monday, May 21, 2012 6:42 PM
> Subject: [DynoMotion] Re: Feedhold with external pushbutton
>
>
>  
>
>
> Good grief!
>
> That is a bunch of code I can't make any sense of....lol.
>
> I mocked up a similar setup of what I posted on my Arduino, and it works most of the time....probably bounce....but i had an idea that I read about for that.
>
> I guess the codes really aren't too similar between the two.
>
> This is going to be tough, because I want to understand what to do rather than rely on you to make what I need. I have 3 other machines that are going to have some special needs and I definitely don't want to pester you too much.
>
> Do you have any recommended reading?
>
> Thanks again,
>
> Mike
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Mike,
> >  
> > There were quite a few issues :}
> >  
> > But I think something else to consider is switch bounce.  Usually mechanical switches do not switch on and off cleanly.  Sometimes it doesn't matter with something like EStop but here where you want to toggle something on and off switch bounce can be a problem.  A noise spike might want to be ignored as well.  So I added a helper function to debounce switches.  This function will handle the messy details and return one of 3 values:  0 if the switch just transitioned low, 1 if it just transitioned high, and -1 if there was no change.  The same (Debounce) function can be used for any number of switches but 3 global variables must be created for each switch and they must be passed to the function.  The function uses these 3 variables to remember what has been going on with that particular switch.  The DBTIME is set at 300 samples which would be about 60ms.
> >  
> > I've uploaded a C Program (FeedHoldCycleStart.c) to your folder that watches two switches.  One for FeedHold and One for Cycle Start (I assume that is what you meant by "Start  GCode").
> >  
> > You may need to tweak it for your bit numbers and polarities.
> >  
> > Regards
> > TK
> >   
> >
> > From: michaelthomasn <michaelniksch@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Monday, May 21, 2012 12:24 PM
> > Subject: [DynoMotion] Feedhold with external pushbutton
> >
> >
> >  
> > Tom,
> >
> > I want to have the feedhold activated by pushing a button, then resume motion by pushing the button again.
> >
> > I think i figured out how to do it.
> >
> > I wondered if you would comment on my c program.
> >
> > It seems unnecessarily complicated to me.....but I couldn't seem to get my non programmer head to come up with anything better.
> >
> > http://tech.groups.yahoo.com/group/DynoMotion/files/michaelthomas/
> >
> > I would also like to start a kmotion cnc g code program with an external button, too.
> >
> > Is there a command for that?
> >
> > Mike
> >
>
Group: DynoMotion Message: 5040 From: Tom Kerekes Date: 5/23/2012
Subject: Re: Feedhold with external pushbutton
Hi Michael,
 
I appreciate you spending effort to improve your C.
 
Your new program is much better.  Here are some critiques:
 
#1 - indentation style.  Although it makes no difference to the compiler how you place "whitespace" (tabs, spaces, newlines).  A human read expects code of the same block to be indented the same.  Otherwise it "hurts" the eye to look at it.  Try to do:
 
if (XXX)
     {
Statement1;
               Statement2;
    Statement3;
}

 
rather than the indentation below that clearly indicates the 3 statements "belong" to the if condition
 
 
if (XXX)
{
    Statement1;
    Statement2;
    Statement3;
}
 
 
#2 - Sampling the input twice with a 10ms delay will help avoid bounce (and noise) but probably not eliminate it entirely.  It is better to check it continuously and only after all the readings match assume the value is valid.
 
#3 - Placing a delay in the code blocks the CPU entirely.  This works for 1 switch or doing 1 thing at a time, but if there are multiple things that all need to be serviceed simultaneously it doesn't work.  This is why the Debounce function has no delays but maintains its state (context) so it can leave immediately and then come back later and restore where it was in the process.  This is why the Debounce function needs the global variables.
 
#4 - I think you have a flaw in where you set the last button state.  That should be inside the if (value!=buttonstate) condition. The way you have it events might be missed in certain noise scenarios.
 
Regards
TK 
 
 
 
Group: DynoMotion Message: 5050 From: michaelthomasn Date: 5/23/2012
Subject: Re: Feedhold with external pushbutton
The nice thing about knowing very little is that even small gains are monumental. :-)

I don't really follow your indention suggestion.

I read some things about the delay issue, yesterday. The debounce program you posted is starting to make some sense.....but I doubt I'll get it for a little while ,yet. I have a lot of reading to do, but I feel like I'm starting to build a small foundation. I will read about global variables next.

I see what you mean by moving up the buttonstate = value a bracket. I followed a tutorial and played around with a somewhat similar Arduino sketch.....and I knew where it should go, but messed it up anyway.

Another thing I noticed was that the switch behaved differently depending on whether it was pulled up or down.....which I eventually figured out that the if(value==1) was changed to if(value==0) would do the same thing....duh. One way, the action would occur as soon as the pushbutton hit bottom, and the other occurred only when the switch was released. But I know you know that....lol.

Its actually been fun....or at least interesting. I'm enjoying the challenge.

Thanks for checking it out,

Mike

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Michael,
>  
> I appreciate you spending effort to improve your C.
>  
> Your new program is much better.  Here are some critiques:
>  
> #1 - indentation style.  Although it makes no difference to the compiler how you place "whitespace" (tabs, spaces, newlines).  A human read expects code of the same block to be indented the same.  Otherwise it "hurts" the eye to look at it.  Try to do:
>  if (XXX)
>      {Statement1;
>                Statement2;
>     Statement3;
> }
>
>  
> rather than the indentation below that clearly indicates the 3 statements "belong" to the if condition
>  
>  
> if (XXX)
> {    Statement1;
>     Statement2;
>     Statement3;
> }
>  
>  
> #2 - Sampling the input twice with a 10ms delay will help avoid bounce (and noise) but probably not eliminate it entirely.  It is better to check it continuously and only after all the readings match assume the value is valid.
>  
> #3 - Placing a delay in the code blocks the CPU entirely.  This works for 1 switch or doing 1 thing at a time, but if there are multiple things that all need to be serviceed simultaneously it doesn't work.  This is why the Debounce function has no delays but maintains its state (context) so it can leave immediately and then come back later and restore where it was in the process.  This is why the Debounce function needs the global variables.
>  
> #4 - I think you have a flaw in where you set the last button state.  That should be inside the if (value!=buttonstate) condition. The way you have it events might be missed in certain noise scenarios.
>  
> Regards
> TK 
>  
>  
>
> ________________________________
> From: michaelthomasn <michaelniksch@...>
> To: DynoMotion@yahoogroups.com
> Sent: Tuesday, May 22, 2012 3:07 PM
> Subject: [DynoMotion] Re: Feedhold with external pushbutton
>  
>
>  
> Those are some very helpful links....Thanks.
>
> I can't absorb too much at one sitting, though.
>
> I found more than a few helpful things today, so far. :)
>
> I know it's not your business to grade peoples c efforts....but if you have any time to do so, and are in need of a chuckle at my expense..... I would be grateful.
>
> After some new found knowledge, I revised the crap program that I
> originally asked you to critique.
>
> http://tech.groups.yahoo.com/group/DynoMotion/files/michaelthomas/
>
> I will surely use what you gave me, I just want to see if I got closer to making some computer sense.
>
> I suppose when I have my mill moving around, I can see for myself.
>
> Thanks again,
>
> Mike
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Come on Mike It isn't really that bad :}
> >  
> > Hopefully if you don't completely understand the debounce function you can easily understand how to use it.  Just call it passing the bit or condition you wish to debounce and it returns -1, 0, or 1.
> >  
> > here are some C reference links in a previous post:
> >  
> > http://tech.groups.yahoo.com/group/DynoMotion/message/3020
> >  
> > Here are some videos:
> >  
> > http://www.cplusplustutor.com/
> >  
> > Most of the on-line videos assume you will be running C on the PC where there is disk and keyboard and a PC based Compiler.  KFLOP is a bit different environment but the basic C syntax of the language is the same.  His videos that closely apply to KFLOP programs would be:
> >  
> > #3 Constants
> >  
> > #4 Operators
> >  
> > #5 Variables
> >  
> > #6 Outputting (printf)
> >  
> > #8 Conditions
> >  
> > #9 If statement
> >  
> > #10 if else
> >  
> > #11 if else if
> >  
> > #12 while loop
> >  
> > #13 for loop
> >  
> > #14 do while loop
> >  
> > #23 Functions
> >  
> > #24 Function Arguments
> >  
> > #25 Returning values
> >  
> >  
> > TK
> >  
> >  
> >
> >  
> >
> > ________________________________
> > From: michaelthomasn <michaelniksch@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Monday, May 21, 2012 6:42 PM
> > Subject: [DynoMotion] Re: Feedhold with external pushbutton
> >
> >
> >  
> >
> >
> > Good grief!
> >
> > That is a bunch of code I can't make any sense of....lol.
> >
> > I mocked up a similar setup of what I posted on my Arduino, and it works most of the time....probably bounce....but i had an idea that I read about for that.
> >
> > I guess the codes really aren't too similar between the two.
> >
> > This is going to be tough, because I want to understand what to do rather than rely on you to make what I need. I have 3 other machines that are going to have some special needs and I definitely don't want to pester you too much.
> >
> > Do you have any recommended reading?
> >
> > Thanks again,
> >
> > Mike
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Mike,
> > >  
> > > There were quite a few issues :}
> > >  
> > > But I think something else to consider is switch bounce.  Usually mechanical switches do not switch on and off cleanly.  Sometimes it doesn't matter with something like EStop but here where you want to toggle something on and off switch bounce can be a problem.  A noise spike might want to be ignored as well.  So I added a helper function to debounce switches.  This function will handle the messy details and return one of 3 values:  0 if the switch just transitioned low, 1 if it just transitioned high, and -1 if there was no change.  The same (Debounce) function can be used for any number of switches but 3 global variables must be created for each switch and they must be passed to the function.  The function uses these 3 variables to remember what has been going on with that particular switch.  The DBTIME is set at 300 samples which would be about 60ms.
> > >  
> > > I've uploaded a C Program (FeedHoldCycleStart.c) to your folder that watches two switches.  One for FeedHold and One for Cycle Start (I assume that is what you meant by "Start  GCode").
> > >  
> > > You may need to tweak it for your bit numbers and polarities.
> > >  
> > > Regards
> > > TK
> > >   
> > >
> > > From: michaelthomasn <michaelniksch@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Monday, May 21, 2012 12:24 PM
> > > Subject: [DynoMotion] Feedhold with external pushbutton
> > >
> > >
> > >  
> > > Tom,
> > >
> > > I want to have the feedhold activated by pushing a button, then resume motion by pushing the button again.
> > >
> > > I think i figured out how to do it.
> > >
> > > I wondered if you would comment on my c program.
> > >
> > > It seems unnecessarily complicated to me.....but I couldn't seem to get my non programmer head to come up with anything better.
> > >
> > > http://tech.groups.yahoo.com/group/DynoMotion/files/michaelthomas/
> > >
> > > I would also like to start a kmotion cnc g code program with an external button, too.
> > >
> > > Is there a command for that?
> > >
> > > Mike
> > >
> >
>
Group: DynoMotion Message: 5051 From: TK Date: 5/23/2012
Subject: Re: Feedhold with external pushbutton
Ok, now you're hooked forever. 

TK

On May 23, 2012, at 8:45 PM, "michaelthomasn" <michaelniksch@...> wrote:

 

The nice thing about knowing very little is that even small gains are monumental. :-)

I don't really follow your indention suggestion.

I read some things about the delay issue, yesterday. The debounce program you posted is starting to make some sense.....but I doubt I'll get it for a little while ,yet. I have a lot of reading to do, but I feel like I'm starting to build a small foundation. I will read about global variables next.

I see what you mean by moving up the buttonstate = value a bracket. I followed a tutorial and played around with a somewhat similar Arduino sketch.....and I knew where it should go, but messed it up anyway.

Another thing I noticed was that the switch behaved differently depending on whether it was pulled up or down.....which I eventually figured out that the if(value==1) was changed to if(value==0) would do the same thing....duh. One way, the action would occur as soon as the pushbutton hit bottom, and the other occurred only when the switch was released. But I know you know that....lol.

Its actually been fun....or at least interesting. I'm enjoying the challenge.

Thanks for checking it out,

Mike

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Michael,
>  
> I appreciate you spending effort to improve your C.
>  
> Your new program is much better.  Here are some critiques:
>  
> #1 - indentation style.  Although it makes no difference to the compiler how you place "whitespace" (tabs, spaces, newlines).  A human read expects code of the same block to be indented the same.  Otherwise it "hurts" the eye to look at it.  Try to do:
>  if (XXX)
>      {Statement1;
>                Statement2;
>     Statement3;
> }
>
>  
> rather than the indentation below that clearly indicates the 3 statements "belong" to the if condition
>  
>  
> if (XXX)
> {    Statement1;
>     Statement2;
>     Statement3;
> }
>  
>  
> #2 - Sampling the input twice with a 10ms delay will help avoid bounce (and noise) but probably not eliminate it entirely.  It is better to check it continuously and only after all the readings match assume the value is valid.
>  
> #3 - Placing a delay in the code blocks the CPU entirely.  This works for 1 switch or doing 1 thing at a time, but if there are multiple things that all need to be serviceed simultaneously it doesn't work.  This is why the Debounce function has no delays but maintains its state (context) so it can leave immediately and then come back later and restore where it was in the process.  This is why the Debounce function needs the global variables.
>  
> #4 - I think you have a flaw in where you set the last button state.  That should be inside the if (value!=buttonstate) condition. The way you have it events might be missed in certain noise scenarios.
>  
> Regards
> TK 
>  
>  
>
> ________________________________
> From: michaelthomasn <michaelniksch@...>
> To: DynoMotion@yahoogroups.com
> Sent: Tuesday, May 22, 2012 3:07 PM
> Subject: [DynoMotion] Re: Feedhold with external pushbutton
>  
>
>  
> Those are some very helpful links....Thanks.
>
> I can't absorb too much at one sitting, though.
>
> I found more than a few helpful things today, so far. :)
>
> I know it's not your business to grade peoples c efforts....but if you have any time to do so, and are in need of a chuckle at my expense..... I would be grateful.
>
> After some new found knowledge, I revised the crap program that I
> originally asked you to critique.
>
> http://tech.groups.yahoo.com/group/DynoMotion/files/michaelthomas/
>
> I will surely use what you gave me, I just want to see if I got closer to making some computer sense.
>
> I suppose when I have my mill moving around, I can see for myself.
>
> Thanks again,
>
> Mike
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Come on Mike It isn't really that bad :}
> >  
> > Hopefully if you don't completely understand the debounce function you can easily understand how to use it.  Just call it passing the bit or condition you wish to debounce and it returns -1, 0, or 1.
> >  
> > here are some C reference links in a previous post:
> >  
> > http://tech.groups.yahoo.com/group/DynoMotion/message/3020
> >  
> > Here are some videos:
> >  
> > http://www.cplusplustutor.com/
> >  
> > Most of the on-line videos assume you will be running C on the PC where there is disk and keyboard and a PC based Compiler.  KFLOP is a bit different environment but the basic C syntax of the language is the same.  His videos that closely apply to KFLOP programs would be:
> >  
> > #3 Constants
> >  
> > #4 Operators
> >  
> > #5 Variables
> >  
> > #6 Outputting (printf)
> >  
> > #8 Conditions
> >  
> > #9 If statement
> >  
> > #10 if else
> >  
> > #11 if else if
> >  
> > #12 while loop
> >  
> > #13 for loop
> >  
> > #14 do while loop
> >  
> > #23 Functions
> >  
> > #24 Function Arguments
> >  
> > #25 Returning values
> >  
> >  
> > TK
> >  
> >  
> >
> >  
> >
> > ________________________________
> > From: michaelthomasn <michaelniksch@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Monday, May 21, 2012 6:42 PM
> > Subject: [DynoMotion] Re: Feedhold with external pushbutton
> >
> >
> >  
> >
> >
> > Good grief!
> >
> > That is a bunch of code I can't make any sense of....lol.
> >
> > I mocked up a similar setup of what I posted on my Arduino, and it works most of the time....probably bounce....but i had an idea that I read about for that.
> >
> > I guess the codes really aren't too similar between the two.
> >
> > This is going to be tough, because I want to understand what to do rather than rely on you to make what I need. I have 3 other machines that are going to have some special needs and I definitely don't want to pester you too much.
> >
> > Do you have any recommended reading?
> >
> > Thanks again,
> >
> > Mike
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Mike,
> > >  
> > > There were quite a few issues :}
> > >  
> > > But I think something else to consider is switch bounce.  Usually mechanical switches do not switch on and off cleanly.  Sometimes it doesn't matter with something like EStop but here where you want to toggle something on and off switch bounce can be a problem.  A noise spike might want to be ignored as well.  So I added a helper function to debounce switches.  This function will handle the messy details and return one of 3 values:  0 if the switch just transitioned low, 1 if it just transitioned high, and -1 if there was no change.  The same (Debounce) function can be used for any number of switches but 3 global variables must be created for each switch and they must be passed to the function.  The function uses these 3 variables to remember what has been going on with that particular switch.  The DBTIME is set at 300 samples which would be about 60ms.
> > >  
> > > I've uploaded a C Program (FeedHoldCycleStart.c) to your folder that watches two switches.  One for FeedHold and One for Cycle Start (I assume that is what you meant by "Start  GCode").
> > >  
> > > You may need to tweak it for your bit numbers and polarities.
> > >  
> > > Regards
> > > TK
> > >   
> > >
> > > From: michaelthomasn <michaelniksch@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Monday, May 21, 2012 12:24 PM
> > > Subject: [DynoMotion] Feedhold with external pushbutton
> > >
> > >
> > >  
> > > Tom,
> > >
> > > I want to have the feedhold activated by pushing a button, then resume motion by pushing the button again.
> > >
> > > I think i figured out how to do it.
> > >
> > > I wondered if you would comment on my c program.
> > >
> > > It seems unnecessarily complicated to me.....but I couldn't seem to get my non programmer head to come up with anything better.
> > >
> > > http://tech.groups.yahoo.com/group/DynoMotion/files/michaelthomas/
> > >
> > > I would also like to start a kmotion cnc g code program with an external button, too.
> > >
> > > Is there a command for that?
> > >
> > > Mike
> > >
> >
>